package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.YellowpagecategoryDAO;
import com.chanyachting.emall.domain.base.BaseYellowpagecategory;

/**
 * This is the object class that relates to the yellowpagecategory table.
 * Any customizations belong here.
 */
public class Yellowpagecategory extends BaseYellowpagecategory {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Yellowpagecategory () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Yellowpagecategory (java.lang.Integer _id) {
		super(_id);
		
		Yellowpagecategory category=(Yellowpagecategory)new YellowpagecategoryDAO().load(Yellowpagecategory.class, _id);
		
		if(category!=null){
			
			try {
				BeanUtils.copyProperties(this, category);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * Constructor for required fields
	 */
	public Yellowpagecategory (
		java.lang.Integer _id,
		java.lang.String _name) {

		super (
			_id,
			_name);
	}
/*[CONSTRUCTOR MARKER END]*/
	
	
	public static List list(){
		
		return new YellowpagecategoryDAO().find("from Yellowpagecategory");
	}
	
	
	public List getSubCategoryList(){
		
		return Yellowpagesubcategory.listByCategoryId(this.getId());
	}
	
	
	public boolean save(){
		
		new YellowpagecategoryDAO().save(this);
		
		return true;
	}
	
	public boolean update(){
		
		new YellowpagecategoryDAO().update(this);
		
		
		return true;
	}
	
	public boolean delete(){
		
		List list=this.getSubCategoryList();
		
		if(list==null || list.size()<1){
		
			new YellowpagecategoryDAO().delete(this);
		
		}else{
			
			return false;
		}
		
		return true;
	}
	
}